<?php

/**
 * @todo: Ersetzen mit Zends Redirector Helper
 *
 */
class WSB_Controller_Helper_Redirect extends Zend_Controller_Action_Helper_Abstract
{

	/**
	 * @param string $url
	 * @param array $params
	 */
	public function direct($url, $params=array())
	{

		$finalUrl = WSB_Div::trimTrailingSlash($url);

	    // Example: /admin/page/list/
	    if(substr($finalUrl, 0, 1) == '/') {
            $finalUrl = 'http://' . WSB_HOST . $finalUrl;
	    }
	    // Example: admin/page/list/
	    elseif(substr($finalUrl, 0, 7) != 'http://') {
            $finalUrl = 'http://' . WSB_HOST . WSB_ADMIN_URL . $finalUrl;

	    }

		if(is_array($params) && (count($params)> 0)) {
			$delim = '/';
			foreach($params AS $key=>$value) {
				$finalUrl .= $delim . $key . $delim . $value;
			}
		}

	    // Url should look like http://www.wsb.test/admin/page/list now.
		$this->getResponse()->setRedirect($finalUrl);
		$this->getResponse()->sendResponse();
		exit;

	}

}